﻿using System;
using System.Globalization;

namespace Circa.Tools {
    static public class UnixTimestampConverter {
        static private DateTime _unixEpoch;
        static private DateTime UnixEpoch {
            get {
                if ( null == _unixEpoch ) {
                    _unixEpoch = new DateTime( 1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc );
                }
                return _unixEpoch;
            }
        }

        static public DateTime FromInt( int timeStamp ) {
            DateTime dt = new DateTime( _unixEpoch.Ticks, DateTimeKind.Utc );
            dt.AddSeconds( timeStamp );
            return dt;
        }

        static public DateTime FromString( string timeStamp ) {
            return FromInt( int.Parse( timeStamp, NumberStyles.Integer ) );
        }

    }

}
